'use strict';
const db = uniCloud.database()
exports.main = async (event, context) => {
	//event为客户端上传的参数
	console.log('event : ', event)
	let {operation,data} = event;
	let res = {};
	const collection = db.collection('travel-store')
	switch (operation){
		case "add":
			res = await collection.add(data);
			res = Object.assign({},res,data);
			break;
		case "get":
		// data 包含：_id && owner
			res = await collection.where(data).get();
			if(res.data.length>0){
				res.data = res.data[0]
			}
			break;
		case "getAll":
		// data 包含：_id && owner
			res = await collection.get();
			break;
		default:
			res = {
			  code: 403,
			  msg: '非法访问'
			}
			break;
	}
	
	
	
	
	
	//返回数据给客户端
	return res
};
